package com.jkhan.design.factory;

import com.jkhan.design.util.ClassLoaderUtils;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @ClassName JDKInvocationHandler
 * @Description JDKInvocationHandler
 * @Author hjk
 * @Date 2023/1/9 22:50
 **/
public class JDKInvocationHandler implements InvocationHandler {

    private ICacheAdapter iCacheAdapter;

    public JDKInvocationHandler(ICacheAdapter iCacheAdapter) {
        this.iCacheAdapter = iCacheAdapter;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return iCacheAdapter.getClass()
                .getMethod(method.getName(), ClassLoaderUtils.getClazzByArgs(args))
                .invoke(iCacheAdapter, args);
    }
}
